package yambal.net.google
{
	import com.adobe.utils.DateUtil;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestHeader;
	
	import yambal.net.google.events.RequesterEvent;
	
	[Event(name="response", type='yambal.net.google.events.RequesterEvent')]
	public class Requester extends EventDispatcher
	{
		
		public var Auth:Authentication;
		
		public function Requester()
		{
		}

		public function request(url:String):void{
			trace("request");
			
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, this.comp);
			
			var authHeader:URLRequestHeader = new URLRequestHeader('Authorization', 'GoogleLogin auth=' + this.Auth.auth);
			var req:URLRequest = new URLRequest();
			req.url = url;
			req.method = "get";
			req.requestHeaders.push(authHeader);
			loader.load(req);
		}
		
		private function comp(e:Event):void{
			var loader:URLLoader = e.currentTarget as URLLoader;

			var x:XML = new XML(loader.data);
			
			
			trace(x);
			this.dispatchEvent(new RequesterEvent(RequesterEvent.RESPONSE, x));
			
			/*
			var feed:IFeed = FeedFactory.getFeedByString(loader.data);
			var items:Array = feed.items;
			//すべてのitemのタイトルを挿入
			for each(var item:IItem in items){
				trace(item.title + "\n\t" + item.authors + "\n\t" + item.id + item.date+ item.content);
			}
			*/
		}
	}
}